<template>
  <div class="container align-c" >
    <div>
      <img class="width-103 height-103" v-if="fileSpace" :src="fileSpace + imgUrl" alt="">
    </div>
    <div class="font-20 font-color-3 align-c font-w">
      <span>{{msg}}</span>
      <span>￥{{price}}</span>
    </div>
    <div class="font-12 font-color-6 flex-col mar-t-20">
      <span>订单编号：{{orderId}}</span>
      <span class="mar-t-10">下单时间：{{ orderData.createTime }}</span>
      <span class="mar-t-10" v-if="orderData.payTime && this.price * 1 > 0">支付时间：{{ orderData.payTime }}</span>
    </div>
    <div class="font-14 btn-group flex-col font-w">
      <div class="detail-btn" @click="queryOrderInfo">
        订单详情
      </div>
      <div class="home-btn mar-t-20" @click="$pt.reLaunch({url: '/pages/home/main'})">
        返回首页
      </div>
    </div>
  </div>
</template>

<script>
// import { getOrder } from '@/api/shop'
import { getProjectOrder } from '@/api/distribution'
export default {
  data() {
    return {
      successFlag: '',
      price: '',
      type: '',
      orderId: '',
      orderData: {},
      imgUrl: ''
    }
  },
  onShow() {
  },
  mounted() {
    console.log(this.getCurrentPage().query)
    this.init()
  },
  methods: {
    init() {
      console.log(this.getCurrentPage().query)
      this.successFlag = this.getCurrentPage().query.successFlag
      this.imgUrl = this.successFlag === '1' ? '/images/pay-success.png' : '/images/pay-fail.png'
      this.price = this.getCurrentPage().query.price
      this.type = this.getCurrentPage().query.resType
      this.orderId = this.getCurrentPage().query.orderId
      if (this.successFlag === '1') {
        this.msg = this.price * 1 > 0 ? '支付成功' : '下单成功'
      } else {
        this.msg = '支付失败'
      }
      const that = this
      wx.setNavigationBarTitle({
        title: that.msg
      })
      this.orderInfo()
    },
    queryOrderInfo() {
      this.$pt.navigateTo({ url: `/pages/personal/order/detail/main?orderId=${this.orderId}` })
    },
    orderInfo() {
      // 订单商品类型： 10：微店商品快递配送 11： 微店商品门店自提 20: 分销商品快递配送 30:微店商品+分销商品快递配送
      this.orderData = {}
      // console.log(this.type)
      getProjectOrder(this.orderId).then((response) => {
        if (response.isError) return
        this.orderData = response.data
      }).catch(() => {
      })
      // if (this.type === '10' || this.type === '11') {
      //   getOrder(this.orderId).then((response) => {
      //     if (response.isError) return
      //     this.orderData = response.data
      //   }).catch(() => {
      //   })
      // } else if (this.type === '20') {
      //   getProjectOrder(this.orderId).then((response) => {
      //     if (response.isError) return
      //     this.orderData = response.data
      //   }).catch(() => {
      //   })
      // }
    }
  }
}
</script>

<style lang="less" scoped>
.container {
  padding-top: 35px;
  .btn-group {
    margin-top: 65px;
    text-align: center;
    &>div{
      width: 242px;
      border-radius: 24px;
      padding-top: 10px;
      padding-bottom: 10px;
    }
    .detail-btn {
      background: #7427FF;
      color: #fff;
    }
    .home-btn {
      color: #7427FF;
      border:1px solid #7427FF;
      background: #fff;
      box-sizing: border-box;
    }
  }
}
</style>